<template>
<div class="jieyue">
<el-card>
      <el-table :data="borrowlist" border stripe>
        <el-table-column type="index" align="center"></el-table-column>
        <el-table-column align="center" label="图片" prop="img" width="120">
            <template slot-scope="scope" >
                    <el-image :src="scope.row.img" fit="fill"></el-image>
                </template>
        </el-table-column>
		    <el-table-column align="center" label="图书" prop="bookname"  ></el-table-column>
        <el-table-column align="center" label="作者" prop="author"  ></el-table-column> 
		    <el-table-column align="center" label="种类 " prop="kind" ></el-table-column> 
        <el-table-column align="center" label="描述" prop="instruction" ></el-table-column> 
        <el-table-column align="center" label="操作 "  >
          <!-- 通过scope拿到这一行的数据-->
          <template slot-scope="scope" >  
                <el-button size="mini" type="danger"  plain  @click="re(scope.row._id)">归还</el-button>
            </template>
        </el-table-column> 
        

      </el-table>
</el-card>
</div>
</template>

<script>
export default {
  data () {
    return {
      borrowlist:{name:"",img:"",bookname:"",author:"",kind:"",instruction:""},
    }
  },
  created(){
    this.getborrowlist()
  },
  methods: {
     async getborrowlist(){
      var username=localStorage.getItem("n")
      const result= await this.$http.get('/borrow/find?name='+username);
      if(result.data.code!==200) {
        return this.$message.error('获取图书列表失败')
      }
      this.borrowlist=result.data.data
      console.log(result.data.data)
    },
    async re(id){ 
      console.log("aaa"); 
      console.log(id);
      const s=await this.$http.get('/borrow/f?_id='+id);
      var na=s.data.data.bookname
      const res= await this.$http.put('/books/return?bookname='+na);
      const r=await this.$http.delete('/borrow/return?_id='+id)
      this.getborrowlist()
    },
  }
}
</script>

<style scoped>
.jieyue{
  height: 438px;
}
.el-breadcrumb{
  height: 30px;
}
.el-card{
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}
.el-table{
  margin-top: 15px;
}
.el-card__body{
  padding: 0;
}
</style>
